<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>4_自定义过滤器之手机号码加星实例</title>
    <script src="../lib/angularjs.js"></script>
</head>

<body ng-app="myApp" ng-controller="myCtrl">
    <table border="1px" width="500px">
        <tr class="bold">
            <td>编号</td>
            <td>名字</td>
            <td>手机号码</td>
        </tr>
        <tr ng-repeat="(k, v) in data">
            <td>{{v.id}}</td>
            <td>{{v.name}}</td>
            <td>{{v.phone | truncate:7}}</td>
        </tr>
    </table>
</body>
<script>
    const myApp = angular.module("myApp", [])
    myApp.controller("myCtrl", ["$scope", function ($scope) {
        $scope.data = [{ id: 1, name: "张一", phone: 12312312312 }, { id: 2, name: "王二", phone: 11223344556 }, { id: 3, name: "李三", phone: 12345678900 }, { id: 4, name: "司马四", phone: 13134434567 }]
    }])
    myApp.filter("truncate", function () {
        return function (text, len) {
            const length = len ? len : 3;
            return String(text).substr(0, 11 - length) + new String("*").repeat(length)
        }
    })
</script>

</html>